﻿using DryWCS.App.ViewModel;
using DryWCS.Service.GlobalVariable;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DryWCS.App.View
{
    /// <summary>
    /// WarehouseView.xaml 的交互逻辑
    /// </summary>
    public partial class WarehouseView : UserControl
    {
        #region Parameter
        private  float CellWidth = 1214f / float.Parse(GV.Line1ColCount.ToString());//32f;
        private  float CellHeight = 220f/float.Parse(GV.Line1LayerCount.ToString());
        #endregion

        #region Constructor 
        public WarehouseView()
        {
            InitializeComponent();
            WarehouseViewModel viewModel = new WarehouseViewModel();
            DataContext = viewModel;
            RenderCell();
        }
        #endregion

        #region Generationg columns
        Cell[,] Line1 = new Cell[GV.Line1ColCount, GV.Line1LayerCount];
        Cell[,] Line2 = new Cell[GV.Line2ColCount, GV.Line2LayerCount];
        private void RenderCell()
        {
            for (int i = 0; i < GV.Line1ColCount * GV.Line1LayerCount; i++)
            {
                Cell cell = new Cell("line1", CellWidth, CellHeight, i % GV.Line1ColCount, i / GV.Line1ColCount);
                cell.HorizontalAlignment = HorizontalAlignment.Left;
                cell.VerticalAlignment = VerticalAlignment.Top;
                cell.Margin = new Thickness(cell.X * CellWidth, cell.Y * CellHeight, 0, 0);
                //cell.Margin = new Thickness(cell.X* 1214f / Convert.ToDouble(GV.Line1ColCount), cell.Y * 100f /Convert.ToDouble (GV.Line1LayerCount), 0, 0);
                //cell.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("Gray"));
                Line1[cell.X, cell.Y] = cell;
                gd_line1.Children.Add(cell);
            }

            for (int i = 0; i < GV.Line2ColCount * GV.Line2LayerCount; i++)
            {
                Cell cell = new Cell("line2", CellWidth, CellHeight, i % GV.Line2ColCount, i / GV.Line2ColCount);
                cell.HorizontalAlignment = HorizontalAlignment.Left;
                cell.VerticalAlignment = VerticalAlignment.Top;
                cell.Margin = new Thickness(cell.X * CellWidth, cell.Y * CellHeight, 0, 0);

               // cell.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("Gray"));
                Line2[cell.X, cell.Y] = cell;
                gd_line2.Children.Add(cell);
            }
        }
        #endregion

    }
}
